home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98b.txt / 000095_icon-group-sender _Fri Jun 19 12:38:33 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  5KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.8/8.8.7) with SMTP id MAA22247
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Fri, 19 Jun 1998 12:38:33 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA28231; Fri, 19 Jun 1998 12:38:23 -0700
  7. To: icon-group@optima.CS.Arizona.EDU
  8. Date: 19 Jun 1998 13:30:56 GMT
  9. From: cdt@post.its.mcw.edu (Chris Tenaglia)
  10. Message-Id: <6mdp6g$k4g@wiscnews.wiscnet.net>
  11. Organization: Medical College of Wisconsin - Milwaukee, WI
  12. Sender: icon-group-request@optima.CS.Arizona.EDU
  13. Subject: CGI progress
  14. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  15. Status: RO
  16. Content-Length: 4413
  17.  
  18. Finally, some progress. Maybe its not the optimal approach,
  19. but given this particular unix environment it can be made
  20. to work well. Here's a summary ...
  21.  
  22. 1. CGI program outputs Content-Type: text/html and a blank line.
  23.  
  24. 2. The output is good HTML
  25.  
  26. 3. The GET method is needed to accept data from a form.
  27.  
  28. 4. There are useful environment variables.
  29.    This is where the input data can be found.
  30.    Icon can parse it quite easily.
  31.  
  32. 5. icont and iconx installed in the CGI directory
  33.  
  34. 6. I used a frontend to run the cgi program. This is because
  35.    we did not have a C compiler to use iconc to make pure
  36.    executables. So then the url looks like cgi-bin/iconx?program...
  37.    and it seemed like parameters/variables beyond 'program'
  38.    where not reachable.
  39.  
  40. ###################################################################
  41. #
  42. # file : docgi.icn
  43. # desc : this program is a cgi learning experiment
  44. # use  : called by cgi in the web server
  45. #
  46. # update         by          what
  47. # 08-jun-1998    tenaglia    initial write
  48. #
  49. global nvp   # name-value table
  50. procedure main(param)
  51.   query := getenv("QUERY_STRING") | "interactive"
  52.   method:= getenv("REQUEST_METHOD") | "interactive"
  53.   path  := getenv("PATH_INFO")      | "unknown"
  54.   remote:= getenv("REMOTE_USER")    | "unknown"
  55.   adrs  := getenv("REMOTE_ADDR")    | "interactive"
  56.  
  57.   log   := open("/db1/local/httpd/cgi-bin/bioet/docgi.log","a")
  58.   write(log,adrs," Accessed DOCGI at ",&dateline," with ",query)
  59.   close(log)
  60.  
  61.   fi := open("/db1/local/httpd/cgi-bin/bioet/docgi.cnt")
  62.   bump := read(fi) + 1
  63.   close(fi)
  64.   fo := open("/db1/local/httpd/cgi-bin/bioet/docgi.cnt","w")
  65.   write(fo,bump)
  66.   close(fo)
  67.  
  68.   nvp := table("n/a")
  69.   parts := parse(query,'&')
  70.   every part := !parts do
  71.     {
  72.     pair := parse(part,'=')
  73.     ident := unurl(pair[1])
  74.     value := unurl(pair[2])
  75.     nvp[ident] := value
  76.     }
  77.   write("Content-type: text/html")
  78.   write("")
  79.   write("<HTML>")
  80.   write("<HEAD>")
  81.   write("<TITLE>This is the CGI Generated Title</TITLE>")
  82.   write("</HEAD>")
  83.   write("<BODY>")
  84.   write("<BODY BGCOLOR=#FFFFFF>")
  85.   write("<H1>Big Header</H1>")
  86.   write("<P><P><P>")
  87.   write("Here's a crazy web page!<P>")
  88.   write("The parameter was :",param[1],"<P>")
  89.   write("The query string var is :",query,"<P>")
  90.   write("<TABLE border=5>")
  91.   write("<TH>Name Parts</TH><TH>Value Parts</TH>")
  92.   write("<TR><TD>NAME</TD><TD>VALUE</TD></TR>")
  93.   every xxx := key(nvp) do
  94.     {
  95.     write("<TR><TD>",xxx,"</TD><TD>",nvp[xxx],"</TD></TR>")
  96.     }
  97.   write("</TABLE>")
  98.   write("<P>")
  99.   write("<P>")
  100.   write("<TABLE BORDER=10>")
  101.   write("<TH>CGI Parameters</TH><TH>CGI Values</TH>")
  102.   write("<TR><TD>Method</TD><TD>",method,"</TD></TR>")
  103.   write("<TR><TD>Path</TD><TD>",path,"</TD></TR>")
  104.   write("<TR><TD>Username</TD><TD>",remote,"</TD</TR>")
  105.   write("<TR><TD>Remote address</TD><TD>",adrs,"</TD></TR>")
  106.   write("<TR><TD>Page counter</TD><TD>",bump,"</TD></TR>")
  107.   write("</TABLE>")
  108.   write("</BODY>")
  109.   write("</HTML>")
  110.   end
  111.  
  112. #
  113. # parse a string into a list with respect to a delimiter
  114. #
  115. procedure parse(line,delims)
  116.   static chars
  117.   chars  := &cset -- delims
  118.   tokens := []
  119.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  120.   return tokens
  121.   end
  122.  
  123. #
  124. # This procedure maps the wierd characters out of cgi query strings
  125. #
  126. procedure unurl(text)
  127.   static  hex
  128.   initial {
  129.           hex := table("")
  130.           hex["0"] := 0 ; hex["1"] := 1 ; hex["2"] := 2 ; hex["3"] := 3
  131.           hex["4"] := 4 ; hex["5"] := 5 ; hex["6"] := 6 ; hex["7"] := 7
  132.           hex["8"] := 8 ; hex["9"] := 9 ; hex["a"] := 10; hex["A"] := 10
  133.           hex["b"] := 11; hex["B"] := 11; hex["c"] := 12; hex["C"] := 12
  134.           hex["d"] := 13; hex["D"] := 13; hex["e"] := 14; hex["e"] := 14
  135.           hex["f"] := 15; hex["F"] := 15
  136.           }
  137.   work  := map(text,"+"," ")
  138.   cache := []
  139.   every i := 1 to *work do if work[i] == "%" then put(cache,i)
  140.   while i := pop(cache) do
  141.    {
  142.    nyb1 := work[i+1]
  143.    nyb2 := work[i+2]
  144.    if (nyb1 == "") | (nyb2 == "") then next
  145.    raw  := hex[nyb1] * 16 + hex[nyb2]
  146.    byte := char(raw)
  147.    work[i+:3] := byte
  148.    }
  149.   return work
  150.   end
  151.  
  152. ###################################################################
  153.  
  154. --
  155. Chris Tenaglia   (system manager)     |  The future foretold,
  156. Medical College of Wisconsin          |  The past explained,
  157. 8701 W. Watertown Plank Rd.           |  The present largely appologized for.
  158. Milwaukee, WI 53226   (414)456-8765   |  Organon to the Doctor
  159.  
  160.